export default {
	getters: {
		user(state) {
			return state.user
		},
		userInfo(state) {
			return state.user.info
		},
		userIsLogin(state) {
			return state.user.isLogin
		},
	},
	state: {
		user: {
			info: {},
			isLogin: false
		}
	},
	mutations: {
		userchange(state, data) {
			state.user = JSON.parse(JSON.stringify(data))
		},
		userinfoChange(state, data) {
			let user = JSON.parse(JSON.stringify(state.user))
			user.info = JSON.parse(JSON.stringify(data))
			state.user = user
		},
		userlogin(state, data) {
			let user = JSON.parse(JSON.stringify(state.user))
			user.info = JSON.parse(JSON.stringify(data))
			user.isLogin = true
			state.user = user
		},
		userlogout(state, datacallback) {
			let user = JSON.parse(JSON.stringify(state.user))
			user.info = {}
			user.isLogin = false
			state.user = user
			if(typeof datacallback === 'function'){
				datacallback()
			}
		},
	},
	actions: {
		['user.change']({
			commit
		}, data) {
			commit('userchange', data)
		},
		['user.info.change']({
			commit
		}, data) {
			commit('userinfoChange', data)
		},
		['user.login']({
			commit
		}, data) {
			commit('userlogin', data)
		},
		['user.logout']({
			commit
		}, data) {
			commit('userlogout', data)
		}
	}
}
